<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../layui/dist/layui.js"/>
</head>
<body>

<div id="view"></div>

<script id="demo2" type="text/html">
    <h3>{{ d.title }}</h3>




    {{#
        var fn = function(){
            var a=  JSON.parse(d.params2);
            return a.modname;
        };
    }}

    {{ fn() }}
</script>
<script src="../layui/dist/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.use(['layer', 'form', 'jquery', 'laytpl'], function () {
        var layer = layui.layer
            , form = layui.form
            , $ = layui.jquery
            , laytpl = layui.laytpl;

        var data = { //数据
            "title": "标题"
            ,"params": {"modname": "列表1", "alias": "内容1", "site": "www.baidu.com"}
            ,"params2": '{"modname": "列表2", "alias": "内容1", "site": "www.baidu.com"}'
        };
        console.log(typeof(data.params2));
        console.log(data);
        // data.params3 = $.parseJSON(data.params2);
        // console.log(typeof(data.params3));
        // console.log(data);
        var getTpl = demo2.innerHTML;
        var view = document.getElementById('view');
        laytpl(getTpl).render(data, function (html) {
            view.innerHTML = html;
        });

    });
</script>
</body>
</html>


